// pages/shop/account.js
var app = getApp();

Page({
  data: {
    onSubmit: false
  },
  onLoad: function (options) {
    this.setData({
      shop: wx.getStorageSync('shop')
    });
  },
  bindAccount: function (e) {
    if (this.data.onSubmit) {
      return false
    } else {
      this.setData({
        onSubmit: true
      })
    }
    wx.showLoading({
      title: '提交中',
      mask: true
    })
    var account = e.detail.value.account;
    var wxaccount = e.detail.value.wxaccount;
    var name = e.detail.value.name;
    var shop_id = this.data.shop.id;
    var that = this;
    var shop = this.data.shop;
    app.func.req('shops/update', {
      id: shop_id,
      alipay_account: account,
      alipay_name: name,
      wxpay_account: wxaccount
    }, 'POST', function (res) {
      wx.hideLoading()
      if (res.code == 'success') {
        wx.showToast({
          title: '保存成功',
          duration: 3000
        });
        shop.alipay_account = account;
        shop.alipay_name = name;
        shop.wxpay_account = wxaccount;
        wx.setStorageSync('shop', shop);
        var pages = getCurrentPages();
        var currPage = pages[pages.length - 1];   //当前页面
        var prevPage = pages[pages.length - 2];  //上一个页面
        prevPage.setData({
          shop: shop
        })
        wx.navigateBack();
      } else {
        wx.showToast({
          title: '提交失败',
          image: '/images/fail.png',
          duration: 3000
        });
      }
      that.setData({
        onSubmit: false
      })
    }, {
        'token': wx.getStorageSync('token')
      });
  },
})